package com.polaris.live.popup

import android.content.Context
import android.view.View
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import com.lxj.xpopup.XPopup
import com.polaris.live.R
import com.polaris.live.databinding.PopupGameListBinding
import com.polaris.live.popup.base.BaseLiveBottomPopupView
import com.polaris.live.resp.back_resp.GameGroupVoResp
import com.polaris.live.widget.GameListView

/**
 * GameListPopup
 *
 * @author Created by 半仙 on 2023/10/16/016 19:29
 */
class GameListPopup(
    context: Context,
    private val roomId: String = "",
    private val gameListResp: List<GameGroupVoResp>? = null
) : BaseLiveBottomPopupView<PopupGameListBinding>(context, { PopupGameListBinding.bind(it) }) {

    override fun getImplLayoutId(): Int {
        return R.layout.popup_game_list
    }

    override fun onCreate() {
        super.onCreate()

        mBinding.apply {
            gameListResp?.forEach {
                val gameListView = GameListView(context).apply {
                    setData(it, roomId)
                    setOnClickCallback {
                        dismiss()
                    }
                }
                llGame.addView(gameListView)
            }
        }
    }

    override fun getCardView(): CardView = mBinding.flBg

    override fun getContentView(): View = mBinding.bottom

    companion object {

        fun show(
            context: Context,
            gameListResp: List<GameGroupVoResp>? = null,
            roomId: String = ""
        ) {
            XPopup.Builder(context)
                .isDestroyOnDismiss(true)
                .hasShadowBg(false)
                .navigationBarColor(ContextCompat.getColor(context, R.color.color_fa1d1928))
                .asCustom(GameListPopup(context, roomId, gameListResp))
                .show()
        }
    }
}